﻿#region Usings

using FluentValidation;
using Yandex.Market.Api.Model;

#endregion

namespace Yandex.Market.Api.Validation
{
    internal class OfferBaseValidator<T>: AbstractValidator<T> where T : OfferBase
    {
        public OfferBaseValidator()
        {
            RuleFor(offer => offer.Price).NotEmpty();
            RuleFor(offer => offer.CategoryIds).NotEmpty().SetCollectionValidator(new CategoryIDValidator());
            RuleFor(offer => offer.CurrencyId).NotEmpty();
            RuleFor(offer => offer.Description).Length(1, 255).When(offer => !string.IsNullOrEmpty(offer.Description));
            RuleFor(offer => offer.SalesNotes).Length(1, 50).When(offer => !string.IsNullOrEmpty(offer.SalesNotes));
            RuleFor(offer => offer.Params).SetCollectionValidator(new ParamValidator()).When(offer => offer.Params != null && offer.Params.Count > 0);
        } 
    }
}